//
//  RemarkTableViewCell.m
//  OAProject
//
//  Created by yhj on 2017/3/13.
//  Copyright © 2017年 cdnunion. All rights reserved.
//  备注

#import "RemarkTableViewCell.h"

@implementation RemarkTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;

        self.remarkTextView.hidden=NO;

        self.backgroundColor=WhiteColor;

        self.userInteractionEnabled=YES;

        // 添加监听器，监听自己的文字改变通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:nil];

    }
    return self;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


-(void)textDidChange
{
    CGFloat h=[Util GetHeightWithText:self.remarkTextView.text width:APPW*3/4-kmargin*2 limitHeight:MAXFLOAT font:16];
    if (self.delegate&&[self.delegate respondsToSelector:@selector(GetTextViewHeightByInputRemarkStr:textViewHeight:cell:)]) {
        [self.delegate GetTextViewHeightByInputRemarkStr:self.remarkTextView.text textViewHeight:h cell:self];

        [_remarkTextView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(h);
        }];
    }
}

// remarkTextView
-(UITextView *)remarkTextView
{
    if (!_remarkTextView) {
        UILabel *titleLabel=[self getLabelWithText:@"备       注" font:Font_Number(16) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*2);
            make.centerY.mas_equalTo(0);
            make.width.mas_equalTo(APPW/4-kmargin*2);
        }];

        _remarkTextView=[UITextView new];
        _remarkTextView.scrollEnabled=NO;
        _remarkTextView.font=Font_Number(16);
        [self.contentView addSubview:_remarkTextView];
        [_remarkTextView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(titleLabel.mas_right);
            make.top.mas_equalTo(kmargin);
            make.right.mas_equalTo(-kmargin*2);
            make.bottom.mas_equalTo(-kmargin);
        }];
    }
    return _remarkTextView;
}

@end
